<template>
  <div class="xtx-checkbox" @click="toggle">
    <i class="iconfont " :class="[modelValue?'icon-checked':'icon-unchecked']"></i>
    <span v-if="$slots.default()"> <slot></slot> </span>
    <span v-else-if="label"> {{label}} </span>
  </div>
</template>

<script>
export default {
  name: 'XtxCheckbox',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    label: {
      type: String,
      default: ''
    }
  },
  setup (props, { emit, slots }) {
    console.log()
    const toggle = () => {
      const temp = !props.modelValue
      emit('update:modelValue', temp)
    }
    return { toggle }
  }
}
</script>

<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>
